package org.finmanager.core;

import javax.swing.*;
import java.awt.event.ActionListener;
import java.util.ArrayList;

/**
 * Created by Kelvin on 22/3/2014.
 * <p/>
 * A popup menu when right click on item
 * for choosing edit or delete function
 */
public class ItemPopUpMenu extends JPopupMenu {
	ItemManagerUI itemManagerUI;
	ArrayList<JMenuItem> menuItems = new ArrayList<JMenuItem>();

	public ItemPopUpMenu(ItemManagerUI itemManagerUI) {
		super();
		this.itemManagerUI = itemManagerUI;
		JMenuItem editMenuItem = new JMenuItem("Edit");
		JMenuItem deleteMenuItem = new JMenuItem("Delete");

		editMenuItem.setActionCommand(ItemManagerController.OPEN_ITEM_INPUT_UI_EDIT);
		deleteMenuItem.setActionCommand(ItemManagerController.DELETE_ITEM);

		menuItems.add(editMenuItem);
		menuItems.add(deleteMenuItem);

		add(editMenuItem);
		add(deleteMenuItem);
	}

	public void addMenuItemListener(ActionListener listener) {
		for (JMenuItem menuItem : menuItems) {
			menuItem.addActionListener(listener);
		}
	}
}
